package com.stcc.portal.controller.login;

import com.stcc.customer.bo.login.PCLoginReqBO;
import com.stcc.customer.bo.login.PCLoginRspBO;
import com.stcc.customer.service.login.PCLoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 描述:pc登录接口
 * 项目名:stcc_gl-parent
 * 包名:com.stcc.portal.controller.login
 * 作者:stcc
 * 创建时间:2021/4/22 17:06
 * 版本:1.0
 */
@Api(tags = "PC登录")
@Slf4j
@RestController
@RequestMapping(value ="PC")
public class PCLoginController {

    @DubboReference
    PCLoginService PCloginService;

    @ApiOperation(tags = "PC登录方法",httpMethod = "POST",value = "/PCLogin")
    @ApiImplicitParam(name = "登录入参对象",value = "PCLoginReqBO")
    @RequestMapping(value ="/PCLogin",method = RequestMethod.POST)
    @ResponseBody
    public PCLoginRspBO PCLogin(HttpServletRequest request, HttpServletResponse response, @RequestBody PCLoginReqBO reqBO){
        String sessionId = request.getSession().getId();
        PCLoginRspBO rspBO =  PCloginService.PCLogin(reqBO);
        rspBO.setSessionId(sessionId);
        Cookie cookie = new Cookie("SESSION", sessionId); // (key,value)
        cookie.setPath("/");
        response.addCookie(cookie);
        return rspBO;

    }
}
